<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字母异位词分组 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
            color: #d4d4d4;
        }
        .keyword { color: #569cd6; }
        .string { color: #ce9178; }
        .comment { color: #6a9955; }
        .function { color: #dcdcaa; }
        .number { color: #b5cea8; }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            flex-shrink: 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center">
            <div class="floating-icon inline-block mb-6">
                <i class="fas fa-layer-group text-6xl opacity-90"></i>
            </div>
            <h1 class="text-5xl font-bold mb-4 serif-font">字母异位词分组</h1>
            <p class="text-xl opacity-90 max-w-2xl mx-auto">
                探索如何使用哈希表和排序算法，优雅地解决字符串分组问题
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description Card -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8 card-hover">
            <div class="flex items-center mb-4">
                <i class="fas fa-puzzle-piece text-3xl gradient-text mr-4"></i>
                <h2 class="text-2xl font-bold">题目描述</h2>
            </div>
            <p class="text-gray-700 text-lg leading-relaxed">
                给定一个字符串数组，将所有字母异位词组合在一起。字母异位词是指由相同字母重新排列形成的字符串。
            </p>
            <div class="mt-6 p-4 bg-purple-50 rounded-lg">
                <p class="text-sm text-purple-700">
                    <i class="fas fa-lightbulb mr-2"></i>
                    示例：["eat", "tea", "tan", "ate", "nat", "bat"] → [["eat","tea","ate"], ["tan","nat"], ["bat"]]
                </p>
            </div>
        </div>

        <!-- Core Concepts -->
        <div class="grid md:grid-cols-2 gap-6 mb-8">
            <div class="bg-white rounded-2xl shadow-lg p-6 card-hover">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-hashtag text-purple-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold">核心算法</h3>
                </div>
                <ul class="space-y-2">
                    <li class="flex items-center text-gray-700">
                        <i class="fas fa-check-circle text-green-500 mr-2"></i>
                        哈希表存储分组
                    </li>
                    <li class="flex items-center text-gray-700">
                        <i class="fas fa-check-circle text-green-500 mr-2"></i>
                        字符排序作为键值
                    </li>
                </ul>
            </div>
            
            <div class="bg-white rounded-2xl shadow-lg p-6 card-hover">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-clock text-blue-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold">复杂度分析</h3>
                </div>
                <ul class="space-y-2">
                    <li class="flex items-center text-gray-700">
                        <i class="fas fa-hourglass-half text-orange-500 mr-2"></i>
                        时间：O(n × k × log k)
                    </li>
                    <li class="flex items-center text-gray-700">
                        <i class="fas fa-memory text-blue-500 mr-2"></i>
                        空间：O(n × k)
                    </li>
                </ul>
            </div>
        </div>

        <!-- Algorithm Visualization -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-project-diagram mr-3 gradient-text"></i>
                算法流程可视化
            </h2>
            <div class="mermaid">
                graph TD
                    A[输入字符串数组] --> B[遍历每个字符串]
                    B --> C[字符排序]
                    C --> D{哈希表中存在?}
                    D -->|是| E[添加到现有分组]
                    D -->|否| F[创建新分组]
                    E --> G[继续下一个]
                    F --> G
                    G --> H{还有字符串?}
                    H -->|是| B
                    H -->|否| I[返回所有分组]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style I fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f3f4f6,stroke:#667eea,stroke-width:2px
                    style D fill:#fef3c7,stroke:#f59e0b,stroke-width:2px
            </div>
        </div>

        <!-- Solution Steps -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6">解题步骤</h2>
            <div class="space-y-4">
                <div class="flex items-start">
                    <div class="step-number">1</div>
                    <div class="ml-4 flex-1">
                        <h4 class="font-semibold text-lg mb-1">创建哈希表</h4>
                        <p class="text-gray-600">初始化一个HashMap，键为排序后的字符串，值为原始字符串列表</p>
                    </div>
                </div>
                
                <div class="flex items-start">
                    <div class="step-number">2</div>
                    <div class="ml-4 flex-1">
                        <h4 class="font-semibold text-lg mb-1">字符排序</h4>
                        <p class="text-gray-600">将每个字符串转换为字符数组并排序，作为分组的唯一标识</p>
                    </div>
                </div>
                
                <div class="flex items-start">
                    <div class="step-number">3</div>
                    <div class="ml-4 flex-1">
                        <h4 class="font-semibold text-lg mb-1">分组存储</h4>
                        <p class="text-gray-600">根据排序后的字符串，将原始字符串添加到对应的分组中</p>
                    </div>
                </div>
                
                <div class="flex items-start">
                    <div class="step-number">4</div>
                    <div class="ml-4 flex-1">
                        <h4 class="font-semibold text-lg mb-1">返回结果</h4>
                        <p class="text-gray-600">将哈希表中的所有值（分组列表）转换为最终结果</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Code Implementation -->
        <div class="bg-white rounded-2xl shadow-lg overflow-hidden mb-8">
            <div class="p-8 pb-0">
                <h2 class="text-2xl font-bold mb-4 flex items-center">
                    <i class="fas fa-code mr-3 gradient-text"></i>
                    代码实现
                </h2>
            </div>
            
            <div class="code-block mx-8 mb-8">
                <div class="code-header">
                    <div class="code-dots">
                        <div class="dot dot-red"></div>
                        <div class="dot dot-yellow"></div>
                        <div class="dot dot-green"></div>
                    </div>
                    <span class="text-gray-400 text-sm">Java</span>
                </div>
                <pre><code><span class="keyword">public</span> <span class="function">List&lt;List&lt;String&gt;&gt;</span> <span class="function">groupAnagrams</span>(<span class="keyword">String[]</span> strs) {
    <span class="comment">// 创建哈希表，键为排序后的字符串，值为原始字符串列表</span>
    <span class="keyword">Map</span>&lt;<span class="keyword">String</span>, <span class="keyword">List</span>&lt;<span class="keyword">String</span>&gt;&gt; groups = <span class="keyword">new</span> <span class="function">HashMap</span>&lt;&gt;();
    
    <span class="comment">// 遍历输入的字符串数组</span>
    <span class="keyword">for</span> (<span class="keyword">String</span> s : strs) {
        <span class="comment">// 将当前字符串转为字符数组并排序</span>
        <span class="keyword">char[]</span> charArray = s.<span class="function">toCharArray</span>();
        <span class="function">Arrays</span>.<span class="function">sort</span>(charArray);
        
        <span class="comment">// 将排序后的字符数组转回字符串作为键</span>
        <span class="keyword">String</span> sortedStr = <span class="keyword">new</span> <span class="function">String</span>(charArray);
        
        <span class="comment">// 如果哈希表中不存在此键，创建一个新的列表</span>
        <span class="keyword">if</span> (!groups.<span class="function">containsKey</span>(sortedStr)) {
            groups.<span class="function">put</span>(sortedStr, <span class="keyword">new</span> <span class="function">ArrayList</span>&lt;&gt;());
        }
        
        <span class="comment">// 将原始字符串添加到对应的分组中</span>
        groups.<span class="function">get</span>(sortedStr).<span class="function">add</span>(s);
    }
    
    <span class="comment">// 返回所有分组的列表</span>
    <span class="keyword">return</span> <span class="keyword">new</span> <span class="function">ArrayList</span>&lt;&gt;(groups.<span class="function">values</span>());
}</code></pre>
            </div>
        </div>

        <!-- Key Insights -->
        <div class="bg-gradient-to-r from-purple-50 to-blue-50 rounded-2xl p-8">
            <h3 class="text-xl font-bold mb-4 